<!--************************************************************************************************-->
<!-- < mainPage.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder & Modifier: Xiaoxin Mo                                                                 -->
<!-- Stu : 10389159                                                                                 -->
<!-- Date: 2013-01-01                                                                             -->
<!-- Destription : add function exist                                                       -->
<!--                                                                                                -->
<!-- Version : 2.1                                                                                  -->
<!--************************************************************************************************-->


<?php 
	include_once("../db/Thesis.php");
	
	class ThesisManager{
		static $instance;
		private $thesis;
		
		public function __construct(){
		}
		
		public static function getInstance(){
			if (self::$instance == null)
				self::$instance = new self();
			return self::$instance;
		}
		
		public function insert($array){
			$thesis = new Thesis($array);
			$thesis->insert();
			return true;
		}
		
		public function delete($array){
			$thesis = new Thesis($array);
			$thesis->delete();
		}
		
		public function update($array){
			$thesis = new Thesis($array);
			$thesis->update();
		}
		
		public function getValueByThesisname($thesisname){
			$thesis = new Thesis(null);
			return $thesis->findValueByThesisname($thesisname);
		}
		
		public function getThesislist($N){
			$thesis = new Thesis(null);
			return $thesis->findNTheses($N);
		}
		
		public function getThesislistByUserID($userID, $N){
			$thesis = new Thesis(null);
			$thesis_names = array();
			
			if ($N == null)
				$thesis_list = $thesis->findThesislistByUserID($userID);
			else
				$thesis_list = $thesis->findNThesesByUserID($userID, $N);
			
			return $thesis_list;
		}
		
		public function getThesisNames($N){
			$thesis_list = $this->getThesislist($N);
			$thesis_names = array();
			
			while($row = mysql_fetch_array($thesis_list))
				$thesis_names[] = $row['Thesisname'];

			return $thesis_names;
		}
		
		public function getThesisNamesByUserID($ID, $N){
			$thesis_list = $this->getThesislistByUserID($ID, $N);
			$thesis_names = array();
			
			while($row = mysql_fetch_array($thesis_list))
				$thesis_names[] = $row['Thesisname'];
			return $thesis_names;
		}
		
		// ============added by xiaoxin=========
		public function exist($name){
			if ($this->getValueByThesisname($name) == null)
				return false;
			return true;
		}
	}
?>